#include<bits/stdc++.h>
using namespace std;
struct ip{
	int a,b,c,d,e;
	bool operator==(const ip&x){
		return a==x.a&&b==x.b&&c==x.c&&d==x.d&&e==x.e;
	}
};
vector<ip> ser;
bool can(ip x){
	if(ser.empty()) return true;
	for(vector<ip>::iterator i=ser.begin();i!=ser.end();i++){
		if(x==*i) return false;
	}
	return true;
}
int can1(ip x){
	if(ser.empty()) return -1;
	for(vector<ip>::iterator i=ser.begin();i!=ser.end();i++){
		if(x==*i) return i-ser.begin()+1;
	}
	return -1;
}
int main(){
	//freopen("network.in","r",stdin);
	//freopen("network.out","w",stdout);
	string name;
	int n,a,b,c,d,e;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>name;
		int ret=scanf("%d.%d.%d.%d:%d",&a,&b,&c,&d,&e);
		if(ret<5||a>255||a<0||b>255||b<0||c>255||c<0||d>255||d<0||e>65535||e<0){
			cout<<"ERR"<<endl;
			continue;
		}
		ip tem={a,b,c,d,e};
		if(name=="Server"){
			if(can(tem)){
				cout<<"OK"<<endl;
				ser.push_back(tem);
			}
			else{
				cout<<"FAIL"<<endl;
			}
		}
		else{
			int ret1=can1(tem);
			if(ret1==-1){
				cout<<"FAIL"<<endl;
			}
			else{
				cout<<ret1<<endl;
			}
		}
	}
	return 0;
}
